package org.spbsu.apco.testing.taskset;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.spbsu.apco.common.task.impl.AdditionTask;
import org.spbsu.apco.common.task.impl.MultiplicationTask;
import org.spbsu.apco.server.taskset.BaseTaskSet;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * User: solozobov
 * Date: 13.11.12
 */

public class EquationTaskSet extends BaseTaskSet {
    private static final Logger LOG = LoggerFactory.getLogger(EquationTaskSet.class);

    private static final Random random = new Random();

    private List<Integer> getRandomDataList() {
        final int size = random.nextInt(5) + 1;
        final List<Integer> result = new ArrayList<Integer>(size);
        for (int i = 0; i < size; i++) {
            result.add(random.nextInt(10) - 5);
        }
        return result;
    }

    @Override
    public void initializeTasks() {
        LOG.info("Equation Summ(Mult(Summ(...), Summ(...), Summ(...)), Summ(...)) will be calculated");
        final MultiplicationTask m1 = new MultiplicationTask();
        final AdditionTask a1 = new AdditionTask();
        final AdditionTask a2 = new AdditionTask();
        final AdditionTask a3 = new AdditionTask();
        final AdditionTask a4 = new AdditionTask();
        final AdditionTask a5 = new AdditionTask();

        m1.addSubTasks(a1, a2, a3);
        a5.addSubTasks(m1, a4);

        addLeafTask(a1, getRandomDataList());
        addLeafTask(a2, getRandomDataList());
        addLeafTask(a3, getRandomDataList());
        addLeafTask(a4, getRandomDataList());
        addTask(a5);
        addTask(m1);
    }
}
